layui.define([ 'form', 'table','userApi'], function(exports) {
	var form = layui.form;
	var userApi = layui.userApi;
	var view = {
			init:function(){
				Lib.initGenrealForm($("#changePasswordForm"),form);
				this.initSubmit();
			},
			initSubmit:function(){
				$("#savePassword").click(function(){
					
					var password1;
					var password2;
					
					var formArray = $("#changePasswordForm").serializeArray();
					
					$.each(formArray, function (i, item) {
						if(item.name=="password"){
							password1 = item.value;
						}
						
						if(item.name=="password2"){
							password2 = item.value;
						}
					});

					if(password1==null||password1==undefined||password1==""||password2==null||password2==undefined||password2==""){
						return;
					}
					
					if(password1!=password2){
						Common.info("两次输入的密码不一致");
						return;
					}

					userApi.changePassword($('#changePasswordForm'),function(){
						Common.info("密码更改成功");
						Lib.closeFrame();
					});
					
				});
				
				$("#savePassword-cancel").click(function(){
					Lib.closeFrame();
				});
			}
				
	}
	
	
	
	 exports('changePassword',view);
	
});